package com.suoluo.zenadmin.dao;

import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.ReturnGeneratedKeys;
import net.paoding.rose.jade.annotation.SQL;

import com.suoluo.zenadmin.vo.BaseInfoMetadata;
import com.suoluo.zenadmin.vo.BaseInfoVO;
import com.suoluo.zenadmin.vo.ImageMetadata;
import com.suoluo.zenadmin.vo.ImageVO;

@DAO
public interface InfoDAO {

//	info_id
//	zhname
//	enname
//	content
//	info_type
//	data_id
//	default_info

	@ReturnGeneratedKeys
	@SQL("insert into tb_base_info(zhname,enname,content,info_type,data_id,default_info) " +
			"values(:1.zhname,:1.enname,:1.content,:1.infoType,:1.dataId,:1.defaultInfo)")
	public int addBaseInfo(BaseInfoMetadata baseInfo);
	
	@SQL("update tb_base_info set zhname=:1.zhname,enname=:1.enname,content=:1.content where info_id=:1.infoId")
	public void updateBaseInfo(BaseInfoMetadata baseInfo);
//	image_id
//	source
//	small
//	midlle
//	normal
//	info_id
	@ReturnGeneratedKeys
	@SQL("insert into tb_image(source,small,middle,normal,info_id) " +
			"values(:1.source,:1.small,:1.middle,:1.normal,:1.infoId)")
	public int addImage(ImageMetadata image);
	
	@SQL("update tb_image set source = :2 where image_id = :1")
	public void updateImage(int imageId,String source);
	
	@SQL("delete from tb_image where info_id = :1.infoId")
	public void deleteImages(List<BaseInfoVO> infos);
	
	@SQL("delete from tb_base_info where data_id = :1 and info_type = :2")
	public void deleteBaseInfo(int dataId,int infoType);
	
	
	@SQL("select * from tb_image where info_id = :1")
	public List<ImageVO> findImages(int infoId);
	
	@SQL("select * from tb_base_info where data_id = :1 and info_type = :2")
	public List<BaseInfoVO> findBaseInfo(int dataId,int infoType);
	
	@SQL("select * from tb_base_info where data_id in (:1) and info_type = :2 and default_info = 1")
	public List<BaseInfoVO> findDefaultBaseInfos(int [] dataIds,int infoType);
	
	@SQL("select * from tb_base_info where ##(:1)")
	public List<BaseInfoVO> findDefaultBaseInfos(String condition);
	
	@SQL("select * from tb_image where image_id=:1")
	public ImageVO findImageById(int imageId);
	
	@SQL("delete from tb_image where image_id=:1")
	public void deleteImage(int imageId);
	
	@SQL("select tb.*,ti.image_id,ti.small,ti.source from tb_base_info tb join tb_image ti on ti.info_id = tb.info_id where tb.info_id =:1")
	public List<BaseInfoVO> findBaseInfoByInfoId(int infoId);
	
	
	@SQL("delete from tb_base_info where info_id=:1")
	public void deleteBaseInfoById(int infoId);
	
	@SQL("select * from tb_base_info where info_id=:1")
	public BaseInfoVO findBaseInfoById(int infoId);
	
	@SQL("select * from tb_image where info_id in (:1)")
	public List<ImageVO> findImages(int [] infoIds);
	
	@SQL("select * from tb_base_info where data_id = :1 and info_type = :2 and default_info = 0")
	public List<BaseInfoVO> findBaseInfoNoDefault(int dataId,int infoType);
}
